<?php
// $Id$

/**
 * Controller_Admin_Trunkbill 控制器
 */
class Controller_Admin_Trunkbill extends Controller_Abstract
{
	function _format_appendSql()
	{
		if (isset($_SESSION['acct']))
		{
			if ($_SESSION['acct']['admin_id'] == -1 && $_SESSION['acct']['agent_id'] == -1)
			{
			//为管理
				//$append['']
				$append['admin_id'] = $_SESSION['acct']['id'];
				
			}else
			{
				$append['admin_id'] = $_SESSION['acct']['admin_id'];
				$append['id'] = Acct::_get_have_acctid($_SESSION['acct']['id'], $_SESSION['acct']['admin_id']);
		
			}
		}
		return $append;
	}
	function actionIndex()
	{
        $this->union_table = Trunkbill::meta();
        $this->lists();
	}
	function actiondel()
	{
		Syslog::logs('删除对入话务:'.$this->_context->ids);
		$this->union_table = Trunkbill::meta();
		$param = $this->_format_appendSql();
		$param['id'] = $this->_context->ids;
		$this->delete($param);
	}
	function actionadd()
	{
		$this->union_table = Trunkbill::meta();
		//ini_set('allow_call_time_pass_reference', true); //开启引用？
		$handle = new helper_autoinsert($this->union_table);
		$form = new Form_trunkbill_add(url($this->_context->controller_name.'/'.$this->_context->action_name));
		$result = $handle->add($form, 'id',$_GET);
		
		if ($this->_context->isGET())
		{
				$result->element('admin_id')->value = Acct::cur_admin_id();
		 		$result->element('agent_id')->value = $_SESSION['acct']['id'];
		 		
		 		$result->element('rategroupid')->items =  Rategroup::_get_arrayinfo(array('agent_id'=>$_SESSION['acct']['id']));
		 		
		 		$result->element('gatewaygroupid')->items = Getewaygroup::_get_arrayinfo();
		 		
			$this->_view['form'] = $result;
			$this->_viewname = '../form/add';
		}else {
			Syslog::logs('编辑对入话务:'.$_POST['accountcode']);
			return call_user_func_array(array($this,$handle->status),array($result));
		}
	}
}


